home *** CD-ROM | disk | FTP | other *** search
/ EnigmA Amiga Run 1996 February / EnigmA AMIGA RUN 04 (1996)(G.R. Edizioni)(IT)[!][issue 1996-02][Skylink CD III].iso / earcd / util1 / syslog.lha / SysLog_V1.00 / Developer / examples / Log / Log.c < prev    next >
C/C++ Source or Header  |  1995-11-13  |  1KB  |  76 lines

  1. /*
  2.  * syslog.library Log()-function example
  3.  *
  4.  * This file is public domain.
  5.  *
  6.  * Author: Petri Nordlund <petrin@megabaud.fi>
  7.  *
  8.  * $Id: Log.c 1.3 1995/10/31 17:33:59 petrin Exp petrin $
  9.  *
  10.  *
  11.  * This program demostrates how to log messages using syslog.library's Log()
  12.  * function.
  13.  *
  14.  */
  15.  
  16. #include <stdio.h>
  17. #include <stdlib.h>
  18. #include <stdarg.h>
  19. #include <proto/exec.h>
  20. #include <dos/dos.h>
  21. #include <proto/syslog.h>
  22. #include <libraries/syslog.h>
  23.  
  24.  
  25. void Error(LONG priority, STRPTR format, ...);
  26.  
  27.  
  28. struct Library *SysLogBase = NULL;
  29.  
  30.  
  31. int
  32. main(int argc, char **argv)
  33. {
  34.     /*
  35.      * First open the syslog.library
  36.      */
  37.     if(!(SysLogBase = OpenLibrary(SYSLOGNAME, SYSLOGVERSION)))
  38.     {
  39.         puts("Can't open \"syslog.library\".");
  40.         exit(RETURN_FAIL);
  41.     }
  42.  
  43.     /*
  44.      * This will create a message "Test: Test message" with priority LOG_NOTICE and
  45.      * facility LOG_USER.
  46.      */
  47.     Log(LOG_USER|LOG_NOTICE, 0, "Test", "Test message", NULL);
  48.  
  49.     /*
  50.      * As above, but include this task's PID in the message and output the
  51.      * message to console also.
  52.      */
  53.     Log(LOG_USER|LOG_NOTICE, LOG_PID|LOG_CONS, "Test", "Test message II", NULL);
  54.  
  55.     /*
  56.      * Use the Error() routine to process var args.
  57.      */
  58.     Error(LOG_USER|LOG_EMERG, "EMERGENCY! %d %s:s landed on my backyard!", 2, "UFO");
  59.  
  60.     if(SysLogBase)
  61.         CloseLibrary(SysLogBase);
  62.  
  63.     return(RETURN_OK);
  64. }
  65.  
  66.  
  67. void
  68. Error(LONG priority, STRPTR format, ...)
  69. {
  70.     va_list args;
  71.  
  72.     va_start(args, format);
  73.     Log(priority, 0, NULL, format, (LONG *) args);
  74.     va_end(args);
  75. }
  76.